package com.yanqu.road.server.cmd.activity.horserun;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.HorseRunProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.horserun.HorseRunActivityModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_HORSE_RUN_OPEN_ADVENTURE_REQ,desc = "小马快跑开启冒险")
public class HorseRunOpenAdventureCmd extends AbstractCommand {

    private int activityId;

    private int multiple;

    private int roadType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HorseRunProto.HorseRunOpenAdventureReq horseRunOpenAdventureReq = HorseRunProto.HorseRunOpenAdventureReq.parseFrom(packet.getBytes());
        activityId = horseRunOpenAdventureReq.getActivityId();
        multiple = horseRunOpenAdventureReq.getMultiple();
        roadType = horseRunOpenAdventureReq.getRoadType();

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(HorseRunActivityModule.class).startNewGame(activityId, multiple,roadType);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            HorseRunProto.HorseRunOpenAdventureResp.Builder resp = HorseRunProto.HorseRunOpenAdventureResp.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_HORSE_RUN_OPEN_ADVENTURE_REQ,resp);
        }
    }
}
